﻿using System.Collections.Generic;
using Identity;

namespace Coder.Workflow
{
    public class WorkTask
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public Role Role { get; set; }

        public bool CanEdit { get; set; }

        public bool CanReject { get; set; } 
        public bool CanGiveUp { get; set; } 
        /// <summary>
        ///     排序用的。
        /// </summary>
        public int Ordered { get; set; } = -1;
        /// <summary>
        /// 默认建议
        /// </summary>
        public string DefaultResolveComment { get; set; }

        protected virtual WorkActivity CreateSingle(ProcessInstance wf)
        {
            if (Role == null) throw new WorkflowException("角色不能为空");
            var result = new WorkActivity
            {
                //  Name = Name,
                ProcessInstance = wf,
                WorkTask = this,
                Role = Role
            };
            return result;
        }
        /// <summary>
        /// 是否能够进入这个task
        /// </summary>
        /// <param name="instalc"></param>
        /// <returns></returns>
        protected internal virtual bool PreCondition(ProcessInstance instalc)
        {
            return true;
        }

        protected internal virtual IEnumerable<WorkActivity> Create(ProcessInstance wf)
        {
            if (Role == null) throw new WorkflowException("角色不能为空");
            return new[] { CreateSingle(wf) };
        }

        public virtual void OnComplete(WorkActivity workActivity, WorkflowDbContext context)
        {
        }
    }
}